package org.jverify.data.pojo;

import java.util.Arrays;

public class FileData {

	private final byte[] signature;
	private final String name;
	private byte[] binaryContent;

	/** full constructor */
	public FileData(final byte[] signature, final String name, final byte[] binaryContent) {
		this.signature = Arrays.copyOf(signature, signature.length);
		this.name = name;
		this.binaryContent = Arrays.copyOf(binaryContent, binaryContent.length);
	}

	public FileData(final byte[] signature, final String name) {
		this.signature = Arrays.copyOf(signature, signature.length);
		this.name = name;
	}

	public byte[] getSignature() {
		return Arrays.copyOf(signature, signature.length);
	}

	public String getFileName() {
		return name;
	}

	public byte[] getBinaryContent() {
		return Arrays.copyOf(binaryContent, binaryContent.length);
	}

	public void setBinaryContent(final byte[] binaryContent) {
		this.binaryContent = Arrays.copyOf(binaryContent, binaryContent.length);
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + Arrays.hashCode(signature);
		return result;
	}

	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof FileData)) {
			return false;
		}
		final FileData other = (FileData) obj;
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		}
		else if (!name.equals(other.name)) {
			return false;
		}
		if (!Arrays.equals(signature, other.signature)) {
			return false;
		}
		return true;
	}
}